/**
 *
 */
package vn.n2n.jaxb;

import java.io.IOException;
import java.util.ArrayList;

/**
 * @author nghi
 *
 */
public class BookMain {

	public static void main(String[] args) throws IOException {

		ArrayList<Book> bookList = new ArrayList<Book>();

		// create books
		Book book1 = new Book();
		book1.setIsbn("978-0060554736");
		book1.setTitle("The Game");
		book1.setAuthor("Neil Strauss");
		book1.setPublisher("Harpercollins");
		bookList.add(book1);

		Book book2 = new Book();
		book2.setIsbn("978-3832180577");
		book2.setTitle("Feuchtgebiete");
		book2.setAuthor("Charlotte Roche");
		book2.setPublisher("Dumont Buchverlag");
		bookList.add(book2);

		// create bookstore, assigning book
		Bookstore bookstore = new Bookstore();
		bookstore.setProcessName("Do_chess_table_left");
		bookstore.setName("Fraport Bookstore");
		bookstore.setLocation("Frankfurt Airport");
		bookstore.setBookList(bookList);

		String xml = XmlUtils.convertToXml(bookstore);

		System.out.println(xml);
		System.out.println(xml.length());
		Bookstore bookstore2 = (Bookstore) XmlUtils.convertToObject(xml, Bookstore.class);

		System.out.println(bookstore2.getProcessName() + "Halaala");
		for (int i = 0; i < bookstore2.getBooksList().toArray().length; i++) {
			System.out.println("Book " + (i + 1) + ": "
					+ bookstore2.getBooksList().get(i).getTitle() + " from "
					+ bookstore2.getBooksList().get(i).getAuthor());
		}

//		Writer w = null;
//		try {
//			w = new FileWriter(BOOKSTORE_XML);
//			m.marshal(bookstore, w);
//		} finally {
//			try {
//				w.close();
//			} catch (Exception e) {
//			}
//		}
//
//		// get variables from our xml file, created before
//		System.out.println();
//		System.out.println("Output from our XML File: ");
//		Unmarshaller um = context.createUnmarshaller();
//		Bookstore bookstore2 = (Bookstore) um.unmarshal(new FileReader(BOOKSTORE_XML));
//
//		for (int i = 0; i < bookstore2.getBooksList().toArray().length; i++) {
//			System.out.println("Book " + (i + 1) + ": "
//					+ bookstore2.getBooksList().get(i).getName() + " from "
//					+ bookstore2.getBooksList().get(i).getAuthor());
//		}

	}
}